class Solution
{
public:
    double myPow(double x, int n)
    {
        return n < 0 ? 1 / dfs(x, n) : dfs(x, n);
    }
    double dfs(double x, int n)
    {
        if (n == 0) return 1;
        double tmp = dfs(x, n / 2);
        return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;
    }
};